package 预习;

import java.util.Arrays;
import java.util.Scanner;

public class 数组倒序02 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] arr = new int[4];

        System.out.println("请输入个整数：");

        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }

        int[] newarr = reverse(arr);

        System.out.println("原数组是" + Arrays.toString(arr));
        System.out.println("翻转后的数组是" + Arrays.toString(newarr));
    }

    public static int[] reverse(int[] arr) {
        int[] newarr = new int[arr.length];

        for (int first = 0, end = arr.length - 1; first <= end; first++, end--) {

            newarr[first] = arr[end];
            newarr[end] = arr[first];

        }
        return newarr;
    }
}
